package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class AutocompleteTag extends BodyTagSupport{

	private static final long serialVersionUID = 1L;
	
	private String idAutocomplete;
	private String form;
	private String value;
	private Boolean disabled;
	private String customClass;
	private String select;
	private Boolean autoFocus;
	private String appendTo;
	private String delay;
	private String minLength;
	private String position;
	private String className;
	private String columnName;
	private String columnStatusName;
	private String columnStatusValue;
	private String atributeStatusName;
	private String keyField;
	private String keyValue;
	private String labelField;
	private String valueField;
	private String customListClass;
	
	@Override
	public int doEndTag() throws JspException {
		
		JspWriter saida = pageContext.getOut();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("idAutocomplete", idAutocomplete);
		request.setAttribute("form", form);
		request.setAttribute("value", value);
		request.setAttribute("disabled", disabled);
		request.setAttribute("customClass", customClass);
		request.setAttribute("select", select);
		request.setAttribute("autoFocus", autoFocus);
		request.setAttribute("appendTo", appendTo);
		request.setAttribute("delay", delay);
		request.setAttribute("minLength", minLength);
		request.setAttribute("position", position);
		request.setAttribute("className", className);
		request.setAttribute("columnName", columnName);
		request.setAttribute("columnStatusName", columnStatusName);
		request.setAttribute("columnStatusValue", columnStatusValue);
		request.setAttribute("atributeStatusName", atributeStatusName);
		request.setAttribute("keyField", keyField);
		request.setAttribute("keyValue", keyValue);
		request.setAttribute("labelField", labelField);
		request.setAttribute("valueField", valueField);
		request.setAttribute("customListClass", customListClass);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/autocomplete.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		} catch (ServletException s) {

			s.printStackTrace();
			
		} catch (IOException e) {
			
			e.printStackTrace();
			
		}
		
		return super.doEndTag();
	}

	public String getIdAutocomplete() {
		return idAutocomplete;
	}

	public void setIdAutocomplete(String idAutocomplete) {
		this.idAutocomplete = idAutocomplete;
	}

	public String getForm() {
		return form;
	}

	public void setForm(String form) {
		this.form = form;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Boolean getDisabled() {
		return disabled;
	}

	public void setDisabled(Boolean disabled) {
		this.disabled = disabled;
	}

	public String getCustomClass() {
		return customClass;
	}

	public void setCustomClass(String customClass) {
		this.customClass = customClass;
	}

	public String getSelect() {
		return select;
	}

	public void setSelect(String select) {
		this.select = select;
	}

	public Boolean getAutoFocus() {
		return autoFocus;
	}

	public void setAutoFocus(Boolean autoFocus) {
		this.autoFocus = autoFocus;
	}

	public String getAppendTo() {
		return appendTo;
	}

	public void setAppendTo(String appendTo) {
		this.appendTo = appendTo;
	}

	public String getDelay() {
		return delay;
	}

	public void setDelay(String delay) {
		this.delay = delay;
	}

	public String getMinLength() {
		return minLength;
	}

	public void setMinLength(String minLength) {
		this.minLength = minLength;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getColumnStatusName() {
		return columnStatusName;
	}

	public void setColumnStatusName(String columnStatusName) {
		this.columnStatusName = columnStatusName;
	}

	public String getColumnStatusValue() {
		return columnStatusValue;
	}

	public void setColumnStatusValue(String columnStatusValue) {
		this.columnStatusValue = columnStatusValue;
	}

	public String getAtributeStatusName() {
		return atributeStatusName;
	}

	public void setAtributeStatusName(String atributeStatusName) {
		this.atributeStatusName = atributeStatusName;
	}

	public String getKeyField() {
		return keyField;
	}

	public void setKeyField(String keyField) {
		this.keyField = keyField;
	}

	public String getKeyValue() {
		return keyValue;
	}

	public void setKeyValue(String keyValue) {
		this.keyValue = keyValue;
	}

	public String getLabelField() {
		return labelField;
	}

	public void setLabelField(String labelField) {
		this.labelField = labelField;
	}

	public String getValueField() {
		return valueField;
	}

	public void setValueField(String valueField) {
		this.valueField = valueField;
	}

	public String getCustomListClass() {
		return customListClass;
	}

	public void setCustomListClass(String customListClass) {
		this.customListClass = customListClass;
	}
	
}
